package cn.com.ourclass.webviewnew.web.tools;

import android.graphics.Bitmap;

import com.hc.framework.utils.StringUtil;
import com.qiniu.android.http.ResponseInfo;
import com.qiniu.android.storage.UpCompletionHandler;
import com.qiniu.android.storage.UploadManager;

import org.json.JSONObject;

import java.io.ByteArrayOutputStream;

/**
 * Created by Administrator on 2017/6/1.
 */

public class Uploadfile {

    public static String Uploadpic(Bitmap bitmap, String qiniutoken) {

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG, 90, baos);
        final byte[] datas = baos.toByteArray();

        String key = StringUtil.getRandomString(8);
        key = key + ".jpg";
        String token = qiniutoken;
        UploadManager uploadManager = new UploadManager();
        uploadManager.put(datas, key, token,
                new UpCompletionHandler() {
                    @Override
                    public void complete(String fkey, ResponseInfo info, JSONObject response) {
                        if (info.isOK()) {

                        } else {

                        }
                    }
                }, null);
        return key;
    }


}
